#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
vector<vector<int>> levelOrder(Node* root) {
    vector<vector<int>> ret;
    if (root == nullptr)
        return ret;
    queue<Node*> q;
    q.push(root);
    while (!q.empty())
    {
        vector<int> v;
        int sz = q.size();
        for (int i = 0; i < sz; i++)
        {
            Node* tmp = q.front();
            q.pop();
            v.push_back(tmp->val);
            for (auto& e : tmp->children)
            {
                if (e != nullptr)
                    q.push(e);
            }
        }
        ret.push_back(v);
    }
    return ret;
}
struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}
    
};
vector<vector<int>> zigzagLevelOrder(TreeNode* root) {
    vector<vector<int>> ret;
    if (root == nullptr)
        return ret;
    queue<TreeNode*> q;
    q.push(root);
    int level = 1;
    while (!q.empty())
    {
        int sz = q.size();
        vector<int> v;
        for (int i = 0; i < sz; i++)
        {
            TreeNode* tmp = q.front();
            q.pop();
            v.push_back(tmp->val);
            if (tmp->left)
                q.push(tmp->left);
            if (tmp->right)
                q.push(tmp->right);
        }
        if (level % 2 == 0)
            reverse(v.begin(), v.end());
        ret.push_back(v);
        level++;
    }
    return ret;
}
int widthOfBinaryTree(TreeNode* root) {
    int ret = 0;
    queue<pair<TreeNode*, int>> q;
    q.push(make_pair(root, 0));
    while (!q.empty())
    {
        ret = max(ret, q.back().second - q.front().second + 1);
        int sz = q.size();
        for (int i = 0; i < sz; i++)
        {
            auto tmp = q.front();
            q.pop();
            if (tmp.first->left)
                q.push(make_pair(tmp.first->left, tmp.second * 2 + 1));
            if (tmp.first->right)
                q.push(make_pair(tmp.first->right, tmp.second * 2 + 2));
        }
    }
    return ret;
}
vector<int> largestValues(TreeNode* root) {
    vector<int> ret;
    if (root == nullptr)
        return ret;
    queue<TreeNode*> q;
    q.push(root);
    while (!q.empty())
    {
        int maxnum = INT_MIN;
        int sz = q.size();
        for (int i = 0; i < sz; i++)
        {
            TreeNode* tmp = q.front();
            q.pop();
            maxnum = max(maxnum, tmp->val);
            if (tmp->left)
                q.push(tmp->left);
            if (tmp->right)
                q.push(tmp->right);
        }
        ret.push_back(maxnum);
    }
    return ret;
}
int main()
{

	return 0;
}